import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class Main {
    public static void main(String[] args) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        // 读取属性文件
        Properties properties = loadPropertiesFile("myapp.properties");

        // 获取配置的类名
        String className = properties.getProperty("bootstrapClass");

        // 加载类
        Class<?> clazz = Class.forName(className);

        // 创建对象
        Object obj = clazz.newInstance();

        // 执行初始化方法
        Method[] methods = clazz.getDeclaredMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(InitMethod.class)) {
                method.invoke(obj);
            }
        }
    }

    private static Properties loadPropertiesFile(String fileName) throws IOException {
        Properties properties = new Properties();
        InputStream inputStream = Main.class.getClassLoader().getResourceAsStream(fileName);
        properties.load(inputStream);
        return properties;
    }
}